Raghav K. Chhetri

07-21-2021

Multiple ways to compute FFT in Python:

  1. numpy.fft
  2. scipy.fftpack -- Considered legacy. SciPy recommends using scipy.fft
  3. scipy.fft
  4. pyfftw
  5. cupy.fft -- NVIDIA's library that evaluates FFTs on GPUs
  6. torch.FFT

1D FFT (for time-series data)

General comments:

fft takes longer if npnts is not a multiple of 2 and even longer if it is a prime

The amplitude spectrum (power spectrum) is generated by plotting 2*np.abs(X)/npnts, instead of simply np.abs(X), versus frequency. This normalization is performed to get the actual amplitude values of the sine waves that we used to generate the signal (3.0, 1.0, and 0.5 at the three frequencies respectively)

The frequency axis can be defined in different ways:


Spurious frequency peaks in Amplitude Spectrum

Let's change the frequencies of the signal to non-integer values. When we do so, we see that the FFT amplitude shows up with spurious frequency peaks

One way to mitigate these additional frequency components is to use a longer signal, as shown below:


2D FFT (working with images)

1. Blurring an image with 2D FFT

Adapted from the following numpy example


2. Gaussian blur implemented using FFT convolution: fftconvolve

Notice the dark borders around the image, due to zero-padding beyond its boundaries. scipy.ndimage.gaussian_filter gets rid of this artifact.


3. Gaussian blur using SciPy.ndimage

Adapted from the following SciPy lecture

Note that a Gaussian filter smooths out the noise and the edges. Median filter averages the noise and preserves the edges better


Band-pass filtering by Difference of Gaussians

Adapted from the following SciKit-Image documentation

Band-pass filters attenuate signal frequencies outside of a range (band) of interest. In image analysis, they can be used to denoise images while at the same time reducing low-frequency artifacts such a uneven illumination. Band-pass filters can be used to find image features such as blobs and edges.

One method for applying band-pass filters to images is to subtract an image blurred with a Gaussian kernel from a less-blurred image. This example shows two applications of the Difference of Gaussians approach for band-pass filtering.

More on DoG here

1. Denoise image and reduce shadows
2. Enhance edges in an image

Diffraction-limited imaging simulation